﻿
using System.Collections.Generic;
namespace InterfaceComponents
{
    /// <summary>
    /// The HUDWrapper class implements the Visitor design pattern. Everytime the value is set,
    /// each component in the componentslist is "visited" by calling their SetValue method.
    /// </summary>
    public class HUDWrapper<T> 
    {
        private T _value;

        public T value
        {
            get {return _value; }
            set
            {
                foreach (HUDComponent component in HUDComponents)
                {
                    component.SetValue(value);
                }
                this._value = value;
            }
        }
        private List<HUDComponent> HUDComponents;
        public HUDWrapper(List<HUDComponent> HUDComponents)
        {
            this.HUDComponents = HUDComponents;
            if (HUDComponents != null)
            {
                foreach (HUDComponent comp in HUDComponents)
                {
                    comp.SetValue(value);
                }
            }
        }

        public void AddComponent(HUDComponent comp)
        {
            HUDComponents.Add(comp);
            comp.SetValue(value);
        }
    }
}

